package view
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	import model.ItemInfo;

	public class Cell extends Sprite
	{
		private var _itemInfo:ItemInfo;
		private var _image:Sprite;
		private var image:Bitmap;
		
		private var loader:Loader=new Loader();
		
		
		public function Cell(itemInfo:ItemInfo)
		{
			this.seTitemInfo(itemInfo);
		}
		
		public function seTitemInfo(info:ItemInfo):void{
			this._itemInfo=info;
			var url:URLRequest=new URLRequest(this._itemInfo.imageURL);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
			loader.load(url);
		}
		
		/**
		 * 添加图片
		 */
		private function onLoaded(e:Event):void{
			
			image=Bitmap(loader.content);
			this.addChild(image);		
		}
	
		
		public function getCopy():Sprite{
			var sprite:Sprite=new Sprite();
			sprite.addChild(this.image);
			return sprite;
		}
		
		public function get itemInfo():ItemInfo{
			return this._itemInfo;
		}
	}
}